Skip to content

GUACAMOLE-1536: return file size and file permission information when uploading files and displaying file directories - #367

Open
bookread-he wants to merge 6 commits into
apache:mainfrom
Lenovo-OSS:master
Open

bookread-he wants to merge 6 commits into
apache:mainfrom
Lenovo-OSS:master

Conversation

@bookread-he

Copy link
Copy Markdown

return file size and file permission information when uploading files and displaying file directories

hezw5 and others added 6 commits February 11, 2022 15:40
2) src/protocols/rdp/ls.c L88 追加json返回值,包含文件大小。
GUACAMOLE-1536: return file size and file permission information when uploading files and displaying file directories
… uploading files and displaying file directories (#2)

* Update sftp.c

remove invalid annotation

* Update ls.c

remove invalid annotation

@necouchman necouchman left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bookread-he: Thank you for the contribution. In addition to the concerns that I have about how the code is implemented (see review comments below), you need to make sure that all of your commit messages are tagged with GUACAMOLE-1536 (looks like only one of them is currently), and, also, you should make sure that your commits are squashed down to a more reasonable number of commits - 6 commits for 2 file changes and 30-ish code lines changed seems a bit excessive, and, without looking at each of the commits, I would image that some of them are changing your previous commits.

Also, just want to make sure it is noted that making changes, here, will almost certainly require changes in the guacamole-client code. Perhaps you're already planning that, but just wanted to mention it.

Comment thread src/common-ssh/sftp.c
"application/octet-stream", attributes.filesize,
attributes.permissions);
}
mimetype = tmpstr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should just re-assign this string to mimetype, as the name mimetype implies that the data carried is the MIME type, not a string of information with various attributes about the file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

This would also break compatibility with any implementation that expects the value to be a mimetype string, which is also what we have defined for the protocol: https://guacamole.apache.org/doc/gug/protocol-reference.html#get-instruction

I think a better approach would be to leverage mimetype parameters to encode the information in a compatible way within the mimetype itself. This would allow the same information to be encoded for other instructions like file, as well. For example:

application/octet-stream;size=12345;mode=0644;uid=123;gid=456

If there are standard parameters for this, we can use them, or failing that we can define our own.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Mike,
I hope you're doing well. It's been some time since our last interaction, and I've taken this period to carefully consider and implement the MIME type encoding approach you recommended for the project.

With your guidance in mind, I've crafted a string that incorporates the additional file attributes as MIME type parameters, ensuring that the original distinction between files and directories is maintained. Here's the updated code snippet:

char property_value[256];

snprintf(property_value, sizeof(property_value), 
         "%s;size=%llu;mode=%o;uid=%d;gid=%d", 
         mimetype, 
         (unsigned long long) attributes.filesize, 
         attributes.permissions & 07777,
         attributes.uid, 
         attributes.gid);

guac_common_json_write_property(user, stream, &list_state->json_state, absolute_path, property_value);

I would be grateful for your feedback on this revision. Does this change correctly reflect the format you envisioned? Your further input would be incredibly valuable.

Thank you for your guidance and patience.

Comment thread src/common-ssh/sftp.c
//adding file size and permission
char tmpstr[150];
if (LIBSSH2_SFTP_S_ISDIR(attributes.permissions)) {
sprintf(tmpstr, "{\"mime\":\"%s\",\"size\":%llu,\"perm\":%lu}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how JSON data is assembled elsewhere in the code - if sprintf is routinely used like this, or if there's a library that handles it? Might be worth checking that out - I'd be a little surprised if all of the other places in the guacd code that assemble JSON do it like this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the various internal guac_common_json_*() functions like guac_common_json_write_property().

Comment thread src/protocols/rdp/ls.c
sprintf(tmpstr, "{\"mime\":\"%s\",\"size\":%lu}",
"application/octet-stream", file->size);
}
mimetype = tmpstr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with above - just assigning this tmpstr back to mimetype doesn't really make sense.

@hemabhavani

Copy link
Copy Markdown

Hey, is there any limitation on file size and file types when uploading/downloading the files?

@mike-jumper

Copy link
Copy Markdown
Contributor

@hemabhavani If you have questions about Guacamole, please use the user@guacamole.apache.org mailing list. See: https://guacamole.apache.org/support/#mailing-lists

This is a pull request, and the conversation here should be specific to the changes proposed by that pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants